package com.example.weight;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import java.util.Iterator;
import java.util.List;

public class APP extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        if(!isLocalAppProcess(getPackageName())){
            return;
        }
    }

    //判断当前进程是否是我的进程
    private boolean isLocalAppProcess(String packName) {
        int myPid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.RunningAppProcessInfo myProcess = null;
        List runningProcesses = activityManager.getRunningAppProcesses();
        if (runningProcesses != null) {
            Iterator var11 = runningProcesses.iterator();
            while (var11.hasNext()) {
                ActivityManager.RunningAppProcessInfo process = (ActivityManager.RunningAppProcessInfo) var11.next();
                Log.i("chuan", "process=" + process.processName + " pid=" + process.pid);
                if (process.pid == myPid) {
                    myProcess = process;
                    break;
                }
            }
        }

        if (myProcess == null) {
            Log.i("chuan", "Could not find running process for %d" + myPid);
            return false;
        } else {
            return myProcess.processName.equals(packName);
        }
    }
}
